import string
import random

from PIL import Image, ImageDraw, ImageFont, ImageOps

OUTPUT_FOLD = "../examples/output/"

def tranferToPic(str):
    img = Image.new("RGB", (150, 150), 0)
    draw = ImageDraw.Draw(img)
    font = ImageFont.truetype("arial.ttf", 30)
    chars_x, chars_y = 0, 0
    for char in str:
        if chars_y>=150:
            return None
        draw.text((chars_x, chars_y), char, (255, 255, 255), font)
        chars_w, chars_h = font.getsize(char)
        chars_x += chars_w
        if chars_x + chars_w > 150:
            chars_x = 0
            chars_y += 50

    img.show()
    img_name = ''.join(random.sample(string.ascii_letters + string.digits, 16)) + '.png'

    img.save(OUTPUT_FOLD + img_name)

    return img_name
